package com.bluesky.jwf.component;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;

import com.bluesky.javawebbrowser.domain.html.tags.form.input.Input;

public class FileField extends Component {

	private String contentType;
	private String fileName;
	private String fieldName;

	private byte[] buffer;

	private Input fileTag;

	@Override
	public void init(String html) {

		super.init(html);

		fileTag = (Input) loadByJwfClass("file");
	}

	@Override
	public void setId(String id) {

		super.setId(id);
		fileTag.setName(getId() + "_file");
	}

	public void setPostBackData(String name, byte[] value) {
		buffer = value;

	}

	public String getContentType() {
		return contentType;
	}

	public void setContentType(String contentType) {
		this.contentType = contentType;
	}

	public String getFileName() {
		return fileName;
	}

	public void setFileName(String fileName) {
		this.fileName = fileName;
	}

	public String getFieldName() {
		return fieldName;
	}

	public void setFieldName(String fieldName) {
		this.fieldName = fieldName;
	}

	public byte[] getBuffer() {
		return buffer;
	}

	public void clearBuffer() {
		buffer = null;
	}

	public boolean isEmpty() {
		return (buffer == null || buffer.length == 0);
	}

}
